package com.web.biz.common;
import java.util.List;

import com.css.sword.kernel.utils.SwordLogUtils;
import com.css.sword.platform.web.controller.BaseDomainCtrl;
import com.css.sword.platform.web.controller.annotations.CTRL;
import com.css.sword.platform.web.event.IReqData;
import com.css.sword.platform.web.event.IResData;
import com.css.sword.platform.web.event.SwordRes;
import com.css.sword.platform.web.fileupload.intimeup.SwordFileItem;
import com.web.common.utils.FileUploadUtiles;
import com.web.common.utils.StringUtil;


@CTRL("UploadCtrl")
public class UploadCtrl extends BaseDomainCtrl {

	private static SwordLogUtils log = SwordLogUtils.getLogger(UploadCtrl.class);
	
	/**
	 * 跳转到上传页面
	 */
	public IResData toUploadPage(IReqData req) throws Exception{

		log.debug("开始进入 UploadCtrl_toUploadPage 方法。");

		IResData res = new SwordRes();
		
		res.addPage("pages/common/upload_shopweb.jsp");
		return res;

	}
	
	
	/**
	 * 上传附件并返回WebFullPath路径
	 * @param req
	 * @return WebFullPath
	 * @throws Exception
	 */
	@SuppressWarnings("unused")
	public IResData uploadFjAndGetPath(IReqData req) throws Exception{

		log.debug("开始进入 UploadCtrl_uploadFjAndGetPath 方法。");

		IResData res = new SwordRes();
		String flag = "false";
		String fj = "";
		try {
			List<SwordFileItem> fjlist = this.getFormUploadList2(req, "form_file", "fj");
			String type = StringUtil.parse2String(req.getForm("form_file").get("type"));
			if ("".equals(type)) {
				res.addAttr("flag", flag);
				return res;
			}
			//依据type类型来判断文件要存放的domain
			if ("shopweb".equals(type)) {
				fj = FileUploadUtiles.uploadFileAndGetFileXML(fjlist,FileUploadUtiles.DOMAIN_SHOPWEB);
			}
			String webpath = StringUtil.parse2String(FileUploadUtiles.getFileElemenstMap(fj).get("WebPath"));
			String webfullpath = StringUtil.parse2String(FileUploadUtiles.getFileElemenstMap(fj).get("WebFullPath"));
			
			if (StringUtil.isNotEmpty(webfullpath)) {
				flag = "true";
				res.addAttr("path", webfullpath);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		res.addAttr("flag", flag);
		return res;

	}

	 		


}